<?php 

require_once('init.php');
require_once('./classes/flags.php');
include('inc/top.php');

$groupeditid = sanitizeString($_REQUEST['id']);

if ($user->data['group_id'] != $mgmtgroup) { echo '<div id="main_yellow"><p>You must be an administrator to view this page.</p></div>'; } else {

if (!$phpbb_groups_enabled) { echo '<div id="main_yellow"><p>phpBB groups integration is not enabled.</p></div>'; } else {

if(empty($groupeditid)) { echo "<div id='main_red'><p>No Group Specified</p></div>"; } else {
$groupflagsq = mysql_query("SELECT * FROM $phpbbdb.sm_groups_phpbb WHERE id='$groupeditid'");
$groupflagsa = mysql_fetch_array($groupflagsq);
$curflags = $groupflagsa['flags'];

$bbgroup_query = mysql_query("SELECT group_name FROM $phpbbdb." . GROUPS_TABLE . " WHERE group_id = '" . $groupeditid . "';") or die(mysql_error());
$bbgroup_result = mysql_fetch_assoc($bbgroup_query);
}
?>

<div id="main_gray"><h1>Edit Group</h1></div>

<?php 

if(isset($_POST['editgroup'])) {

$flags = $_POST['a'].$_POST['b'].$_POST['c'].$_POST['d'].$_POST['e'].$_POST['f'].$_POST['g'].$_POST['h'].$_POST['i'].$_POST['j'].$_POST['k'].$_POST['l'].$_POST['m'].$_POST['n'].$_POST['z'].$_POST['o'].$_POST['p'].$_POST['q'].$_POST['r'].$_POST['s'].$_POST['t'];

$input_flags = sanitizeString($flags);
$input_immunity = sanitizeString($_POST['form_immunity']);

mysql_query("UPDATE sm_groups_phpbb SET flags='$input_flags', immunity_level='$input_immunity' WHERE id='$groupeditid'") or die(mysql_error());
echo "<a href='groups_phpbb.php'><div id='main_green'><p>Group Edited Sucessfully!</p></div></a>";
} else {
?>

<form method="post" name="Add Ban" action="editgroup_phpbb.php?id=<?php  echo $groupeditid; ?>">

<table class="table" id="tableborder" cellspacing="0" cellpadding="5" align="center">
	<tr><td align="right"><b>Name:</b></td><td align="left"><input name="form_groupname" type="text" class="searchinput" value="<?php  echo $bbgroup_result['group_name']; ?>" /></td></tr>
	<tr><td align="right"><b>Flags:</b></td><td align="left">
	
		<?php 
			for ($i = 0; $i <= 20; $i++) {
		?><input type="checkbox" name="<?php 
			echo $flag['flag'][$i];
		?>" value="<?php 
			echo $flag['flag'][$i];
		?>"<?php  
			if (stristr($curflags, $flag['flag'][$i])) {
			echo ' checked ';
			}
			?> />
			<?php  echo $flag['name'][$i]; ?><br/><?php  } ?>

	</td></tr>		
	<tr><td align="right"><b>Immunity:</b></td><td align="left"><input name="form_immunity" type="text" class="searchinput" value="<?php  echo $groupflagsa['immunity_level']; ?>" /></td></tr>
	
	<tr><td colspan="2" align="center">
		<input name="editgroup" type="submit" value="Edit Group" class="searchbutton" /> 
		<form action="editgroup_phpbb.php?id=<?php  echo $groupeditid; ?>" method="post"><input type="submit" name="deletegroup" value="Delete Group" class="searchbutton" /></form>
	</td></tr>
</table>
</form>

<?php  

if(isset($_POST['deletegroup'])) {

mysql_query("DELETE FROM sm_groups_phpbb WHERE id='$groupeditid'") or die(mysql_error());
redirect('groups_phpbb.php');
}
}
}
}

include('inc/bottom.php'); 

?>